//
//  MineTransformViewController.m
//  renmingongshe
//
//  Created by macbook on 2017/11/8.
//  Copyright © 2017年 xiaodian. All rights reserved.
//

#import "MineTransformViewController.h"
#import "ZSDPaymentForm.h"
#import "ZSDPaymentView.h"

@interface MineTransformViewController ()
@property (weak, nonatomic) IBOutlet UILabel *MoneyLabel;
@property (weak, nonatomic) IBOutlet UITextField *MoneyTF;
@property (weak, nonatomic) IBOutlet UITextField *CountTF;
@property (weak, nonatomic) IBOutlet UITextField *NameTF;

@end

@implementation MineTransformViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.titleLabel.text = @"转账";
    _MoneyTF.keyboardType = UIKeyboardTypeDecimalPad;
    self.view.backgroundColor = [UIColor colorWithHex:0xf2f2f2];
    
    [self downloadData];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getPassword:) name:@"GetPassword" object:nil];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [_MoneyTF resignFirstResponder];
    [_CountTF resignFirstResponder];
    [_NameTF resignFirstResponder];
}

- (void)downloadData
{
    [self.view loadingOnAnyView];
    [THWManager PostHttp:API(MineTransfrom) Parameters:@{@"userToken":[Utils getUserToken]} Success:^(id responseObject) {
        [self.view removeAnyView];
        _MoneyLabel.text = [NSString stringWithFormat:@"剩余奖励：%@", responseObject[@"data"]];
    } andFalse:^(NSError *error) {
        [self.view removeAnyView];
    }];
}

- (IBAction)SubmitClick:(UIButton *)sender {
    [self showKeyboard];
}

- (void)showKeyboard
{
    ZSDPaymentView *payment = [[ZSDPaymentView alloc]init];
    payment.title = @"请输入支付密码";
    payment.goodsName = @"零钱";
    payment.amount = [_MoneyTF.text floatValue];
    [payment show];
}

- (void)getPassword:(NSNotification *)notice{
    [self.view loadingOnAnyView];
    [THWManager PostHttp:API(MineTransfromClick) Parameters:@{@"userToken":[Utils getUserToken], @"money":_MoneyTF.text, @"user":_CountTF.text, @"payPwd":notice.object, @"debtname":_NameTF.text} Success:^(id responseObject) {
        [self.view removeAnyView];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dismiss" object:nil];
        if ([String(responseObject[@"status_code"]) isEqualToString:@"1001"]) {
            [self.view Message:responseObject[@"msg"]];
        }else{
            
        }
    } andFalse:^(NSError *error) {
        [self.view removeAnyView];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
